package com.javaee.controller.admin;
import com.javaee.BeforeBaseController;
import com.javaee.entity.Mzgh;

import com.javaee.service.admin.MzghService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/admin")
public class MzghController extends BeforeBaseController {

    @Autowired
    private MzghService mzghService;
    @RequestMapping("/mzgh")
    public String queryMzghList(Model model, Integer currentPage){
        int totalCount = mzghService.selectCount();
        int pageSize = 5;
        int totalPage = (int)Math.ceil(totalCount*1.0/pageSize);
        List<Mzgh> mzghList = mzghService.findAllMzghByPage((currentPage-1)*pageSize, pageSize);
//
        model.addAttribute("mzghList",mzghList);
        model.addAttribute("totalPage", totalPage);
        model.addAttribute("currentPage", currentPage);
        return "/admin/mzgh";
    }
    @RequestMapping("/search")
    public String search(Model model,String mykey){

        model.addAttribute("mzghList",mzghService.search(mykey));
        return "/admin/mzgh";
    }
}
